package com.yanqu.road.server.cmd.strongholdwar;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.StrongholdWarCrossProto;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.strongholdwar.StrongholdWarMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = CrossProtocol.C_CROSS_STRONGHOLD_DONATE_ITEM_PROCESS,desc = "")
public class CrossStrongholdDonateItemProcessCmd extends CrossUnionCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        StrongholdWarCrossProto.StrongholdCrossDonateItemProcessReqMsg reqMsg = StrongholdWarCrossProto.StrongholdCrossDonateItemProcessReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        String unionId = reqMsg.getUnionId();
        List<Integer> donateItemProcess = StrongholdWarMgr.getDonateItemProcess(activityId, unionId);
        StrongholdWarProto.StrongholdItemDonateDataRespMsg.Builder msg = StrongholdWarProto.StrongholdItemDonateDataRespMsg.newBuilder();
        StrongholdWarProto.StrongholdItemDonateDataMsg.Builder dataMsg = StrongholdWarProto.StrongholdItemDonateDataMsg.newBuilder();
        for (int i = 0; i < donateItemProcess.size(); i++) {
            StrongholdWarProto.StrongholdItemDonateTempMsg.Builder tempMsg = StrongholdWarProto.StrongholdItemDonateTempMsg.newBuilder();
            tempMsg.setType(i);
            tempMsg.setValue(donateItemProcess.get(i));
            dataMsg.addDonateMsg(tempMsg);
        }
        msg.setData(dataMsg);
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_STRONGHOLD_WAR_ITEM_DONATE_DATA, msg);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), message);
    }

    @Override
    public void sendData() {

    }
}
